import { makeAutoObservable } from 'mobx';
import { RecordKeys, Storage } from './storage';

interface UserScheme {
    avatar: string;
    user_id: string;
    email: string;
    armarium_science_user_birthday: string;
    armarium_science_user_name: string;
    armarium_science_user_sex: string;
    armarium_science_user_sg: string;
    armarium_science_user_tz: string
    blood_pressure: number | string;
    circle_id: number;
    heart_rate: number | string;
    is_yjh_user: number;
    has_yjh: number;
    token: string;
    [key: string]: any;
}

interface SteWard {
    status: number,
    uid: string
}
type Role = 'Acupoints' | 'Doctor' | "Main"
class UserStore {
    me = {} as UserScheme;
    circle_id: number = 0 // 群聊id
    toGuardinMobile: string = ''//被监护人的手机号
    recalledUser: boolean = false;
    login: boolean = false;
    mallToken: string = '';// 百家益673token
    userBindDeviceData: any = []; // 获取已经绑定的设备列表
    isRole = 'Main' as Role // me自己身份、doctor医生身份、guardin监护端、acupoints五穴同频
    autoConnectDeviceSn = ''// 自动连接设备编号
    userDeviceYY01Data: any = [] // 用户YY01设备
    constructor() {
        makeAutoObservable(this);
    }
    // 手机号登录
    signIn(user: UserScheme) {
        this.me = user;
        this.login = true;
        this.recalledUser = true;
        Storage.setItem(RecordKeys.me, user);
    }
    selectRole(type: 'Acupoints' | 'Doctor' | "Main") {
        Storage.setItem(RecordKeys.roles, type);
        this.isRole = type
    }
    //退出登录
    signOut() {
        this.me = {} as UserScheme;
        this.login = false;
        this.recalledUser = false;
        this.mallToken = ''
        this.circle_id = 0
        this.toGuardinMobile = ''
        this.userBindDeviceData = []
        this.userDeviceYY01Data = []
        this.isRole = 'Main'
        Storage.removeItem(RecordKeys.me)
        Storage.removeItem(RecordKeys.pktCount)
        Storage.removeItem(RecordKeys.roles)
        Storage.removeItem(RecordKeys.titleId)
    }

    // 更新用户信息
    changeUserInfo(data) {
        Object.assign(this.me, data)
        Storage.setItem(RecordKeys.me, this.me);
    }
    signAutoConnectDevice(sn) {
        this.autoConnectDeviceSn = sn
        Storage.setItem(RecordKeys.autoConnectDeviceSn, sn)
    }
}
export default new UserStore();
